# -*- coding: utf-8 -*-
"""
@Time ： 2021/8/6 21:20
@Auth ： Mr.掌心 2929184523
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：请输入模块功能描述
"""

#获取当前文件的绝对路径
import logging
import os

import yaml

path = os.path.split(os.path.realpath(__file__))[0]
projectname = 'MyTestFrame09'

#处理：是不是主入口运行
if path.endswith(projectname):
    pass
else:
    idx = path.find(projectname)
    path = path[:idx + len(projectname)]


#读取配置文件
with open(file=path + "/lib/conf.yaml", mode='r', encoding='utf-8') as file:
    logging_yaml = yaml.load(stream=file, Loader=yaml.FullLoader).get('logger')
    logging_yaml['filename'] = path + logging_yaml.get('filename')

    handler = [logging.FileHandler(filename=logging_yaml['filename'],encoding='utf-8')]
    logging_yaml.pop('filename')
    logging_yaml.pop('filemode')
    #配置logging日志：就是从文件中读取handler、formatter、logger记录器配置
    logging.basicConfig(handlers=handler, **logging_yaml)

#获取根记录器：配置信息从yaml配置文件中获取，只会输出到日志文件
logger = logging.getLogger()
#创建输出到控制台
console = logging.StreamHandler()
#设置日志级别
console.setLevel(logging_yaml['level'])
#设置日志格式
console.setFormatter(logging.Formatter(logging_yaml['format']))
#添加到logger输出
logger.addHandler(console)

if __name__ == '__main__':
    logger.debug("DEBUG")
    logger.info("INFO")
    logger.warning("WARNING")
    logger.error("ERROR")
    # try:
    #     int('a')
    # except Exception as e:
    #     logger.exception(e)
    # print(type(1,2) == tuple)











